<!DOCTYPE html>


<html lang="zh-CN">


<head>
  <meta charset="utf-8" />
    
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    最新整理之--docker-compose参数及命令.md |  
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-docker/最新整理之--docker-compose参数及命令"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  最新整理之--docker-compose参数及命令.md
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/11/11/docker/%E6%9C%80%E6%96%B0%E6%95%B4%E7%90%86%E4%B9%8B--docker-compose%E5%8F%82%E6%95%B0%E5%8F%8A%E5%91%BD%E4%BB%A4/" class="article-date">
  <time datetime="2020-11-10T16:00:00.000Z" itemprop="datePublished">2020-11-11</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/docker/">docker</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> 字数统计:</span>
            <span class="post-count">7.9k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> 阅读时长≈</span>
            <span class="post-count">32 分钟</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="最新整理之–docker-compose参数及命令"><a href="#最新整理之–docker-compose参数及命令" class="headerlink" title="最新整理之–docker-compose参数及命令"></a>最新整理之–docker-compose参数及命令</h1><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br><span class="line">534</span><br><span class="line">535</span><br><span class="line">536</span><br><span class="line">537</span><br><span class="line">538</span><br><span class="line">539</span><br><span class="line">540</span><br><span class="line">541</span><br><span class="line">542</span><br><span class="line">543</span><br><span class="line">544</span><br><span class="line">545</span><br><span class="line">546</span><br><span class="line">547</span><br><span class="line">548</span><br><span class="line">549</span><br><span class="line">550</span><br><span class="line">551</span><br><span class="line">552</span><br><span class="line">553</span><br><span class="line">554</span><br><span class="line">555</span><br><span class="line">556</span><br><span class="line">557</span><br><span class="line">558</span><br><span class="line">559</span><br><span class="line">560</span><br><span class="line">561</span><br><span class="line">562</span><br><span class="line">563</span><br><span class="line">564</span><br><span class="line">565</span><br><span class="line">566</span><br><span class="line">567</span><br><span class="line">568</span><br><span class="line">569</span><br><span class="line">570</span><br><span class="line">571</span><br><span class="line">572</span><br><span class="line">573</span><br><span class="line">574</span><br><span class="line">575</span><br><span class="line">576</span><br><span class="line">577</span><br><span class="line">578</span><br><span class="line">579</span><br><span class="line">580</span><br><span class="line">581</span><br><span class="line">582</span><br><span class="line">583</span><br><span class="line">584</span><br><span class="line">585</span><br><span class="line">586</span><br><span class="line">587</span><br><span class="line">588</span><br><span class="line">589</span><br><span class="line">590</span><br><span class="line">591</span><br><span class="line">592</span><br><span class="line">593</span><br><span class="line">594</span><br><span class="line">595</span><br><span class="line">596</span><br><span class="line">597</span><br><span class="line">598</span><br><span class="line">599</span><br><span class="line">600</span><br><span class="line">601</span><br><span class="line">602</span><br><span class="line">603</span><br><span class="line">604</span><br><span class="line">605</span><br><span class="line">606</span><br><span class="line">607</span><br><span class="line">608</span><br><span class="line">609</span><br><span class="line">610</span><br><span class="line">611</span><br><span class="line">612</span><br><span class="line">613</span><br><span class="line">614</span><br><span class="line">615</span><br><span class="line">616</span><br><span class="line">617</span><br><span class="line">618</span><br><span class="line">619</span><br><span class="line">620</span><br><span class="line">621</span><br><span class="line">622</span><br><span class="line">623</span><br><span class="line">624</span><br><span class="line">625</span><br><span class="line">626</span><br><span class="line">627</span><br><span class="line">628</span><br><span class="line">629</span><br><span class="line">630</span><br><span class="line">631</span><br><span class="line">632</span><br><span class="line">633</span><br><span class="line">634</span><br><span class="line">635</span><br><span class="line">636</span><br><span class="line">637</span><br><span class="line">638</span><br><span class="line">639</span><br><span class="line">640</span><br><span class="line">641</span><br><span class="line">642</span><br><span class="line">643</span><br><span class="line">644</span><br><span class="line">645</span><br><span class="line">646</span><br><span class="line">647</span><br><span class="line">648</span><br><span class="line">649</span><br><span class="line">650</span><br><span class="line">651</span><br><span class="line">652</span><br><span class="line">653</span><br><span class="line">654</span><br><span class="line">655</span><br><span class="line">656</span><br><span class="line">657</span><br><span class="line">658</span><br><span class="line">659</span><br><span class="line">660</span><br><span class="line">661</span><br><span class="line">662</span><br><span class="line">663</span><br><span class="line">664</span><br><span class="line">665</span><br><span class="line">666</span><br><span class="line">667</span><br><span class="line">668</span><br><span class="line">669</span><br><span class="line">670</span><br><span class="line">671</span><br><span class="line">672</span><br><span class="line">673</span><br><span class="line">674</span><br><span class="line">675</span><br><span class="line">676</span><br><span class="line">677</span><br><span class="line">678</span><br><span class="line">679</span><br><span class="line">680</span><br><span class="line">681</span><br><span class="line">682</span><br><span class="line">683</span><br><span class="line">684</span><br><span class="line">685</span><br><span class="line">686</span><br><span class="line">687</span><br><span class="line">688</span><br><span class="line">689</span><br><span class="line">690</span><br><span class="line">691</span><br><span class="line">692</span><br><span class="line">693</span><br><span class="line">694</span><br><span class="line">695</span><br><span class="line">696</span><br><span class="line">697</span><br><span class="line">698</span><br><span class="line">699</span><br><span class="line">700</span><br><span class="line">701</span><br><span class="line">702</span><br><span class="line">703</span><br><span class="line">704</span><br><span class="line">705</span><br><span class="line">706</span><br><span class="line">707</span><br><span class="line">708</span><br><span class="line">709</span><br><span class="line">710</span><br><span class="line">711</span><br><span class="line">712</span><br><span class="line">713</span><br><span class="line">714</span><br><span class="line">715</span><br><span class="line">716</span><br><span class="line">717</span><br><span class="line">718</span><br><span class="line">719</span><br><span class="line">720</span><br><span class="line">721</span><br><span class="line">722</span><br><span class="line">723</span><br><span class="line">724</span><br><span class="line">725</span><br><span class="line">726</span><br><span class="line">727</span><br><span class="line">728</span><br><span class="line">729</span><br><span class="line">730</span><br><span class="line">731</span><br><span class="line">732</span><br><span class="line">733</span><br><span class="line">734</span><br><span class="line">735</span><br><span class="line">736</span><br><span class="line">737</span><br><span class="line">738</span><br><span class="line">739</span><br><span class="line">740</span><br><span class="line">741</span><br><span class="line">742</span><br><span class="line">743</span><br><span class="line">744</span><br><span class="line">745</span><br><span class="line">746</span><br><span class="line">747</span><br><span class="line">748</span><br><span class="line">749</span><br><span class="line">750</span><br><span class="line">751</span><br><span class="line">752</span><br><span class="line">753</span><br><span class="line">754</span><br><span class="line">755</span><br><span class="line">756</span><br><span class="line">757</span><br><span class="line">758</span><br><span class="line">759</span><br><span class="line">760</span><br><span class="line">761</span><br><span class="line">762</span><br><span class="line">763</span><br><span class="line">764</span><br><span class="line">765</span><br><span class="line">766</span><br><span class="line">767</span><br><span class="line">768</span><br><span class="line">769</span><br><span class="line">770</span><br><span class="line">771</span><br><span class="line">772</span><br><span class="line">773</span><br><span class="line">774</span><br><span class="line">775</span><br><span class="line">776</span><br><span class="line">777</span><br><span class="line">778</span><br><span class="line">779</span><br><span class="line">780</span><br><span class="line">781</span><br><span class="line">782</span><br><span class="line">783</span><br><span class="line">784</span><br><span class="line">785</span><br><span class="line">786</span><br><span class="line">787</span><br><span class="line">788</span><br><span class="line">789</span><br><span class="line">790</span><br><span class="line">791</span><br><span class="line">792</span><br><span class="line">793</span><br><span class="line">794</span><br><span class="line">795</span><br><span class="line">796</span><br><span class="line">797</span><br><span class="line">798</span><br><span class="line">799</span><br><span class="line">800</span><br><span class="line">801</span><br><span class="line">802</span><br><span class="line">803</span><br><span class="line">804</span><br><span class="line">805</span><br><span class="line">806</span><br><span class="line">807</span><br><span class="line">808</span><br><span class="line">809</span><br><span class="line">810</span><br><span class="line">811</span><br><span class="line">812</span><br><span class="line">813</span><br><span class="line">814</span><br><span class="line">815</span><br><span class="line">816</span><br><span class="line">817</span><br><span class="line">818</span><br><span class="line">819</span><br><span class="line">820</span><br><span class="line">821</span><br><span class="line">822</span><br><span class="line">823</span><br><span class="line">824</span><br><span class="line">825</span><br><span class="line">826</span><br><span class="line">827</span><br><span class="line">828</span><br><span class="line">829</span><br><span class="line">830</span><br><span class="line">831</span><br><span class="line">832</span><br><span class="line">833</span><br><span class="line">834</span><br><span class="line">835</span><br><span class="line">836</span><br><span class="line">837</span><br><span class="line">838</span><br><span class="line">839</span><br><span class="line">840</span><br><span class="line">841</span><br><span class="line">842</span><br><span class="line">843</span><br><span class="line">844</span><br><span class="line">845</span><br><span class="line">846</span><br><span class="line">847</span><br><span class="line">848</span><br><span class="line">849</span><br><span class="line">850</span><br><span class="line">851</span><br><span class="line">852</span><br><span class="line">853</span><br><span class="line">854</span><br><span class="line">855</span><br><span class="line">856</span><br><span class="line">857</span><br><span class="line">858</span><br><span class="line">859</span><br><span class="line">860</span><br><span class="line">861</span><br><span class="line">862</span><br><span class="line">863</span><br><span class="line">864</span><br><span class="line">865</span><br><span class="line">866</span><br><span class="line">867</span><br><span class="line">868</span><br><span class="line">869</span><br><span class="line">870</span><br><span class="line">871</span><br><span class="line">872</span><br><span class="line">873</span><br><span class="line">874</span><br><span class="line">875</span><br><span class="line">876</span><br><span class="line">877</span><br><span class="line">878</span><br><span class="line">879</span><br><span class="line">880</span><br><span class="line">881</span><br><span class="line">882</span><br><span class="line">883</span><br><span class="line">884</span><br><span class="line">885</span><br><span class="line">886</span><br><span class="line">887</span><br><span class="line">888</span><br><span class="line">889</span><br><span class="line">890</span><br><span class="line">891</span><br><span class="line">892</span><br><span class="line">893</span><br><span class="line">894</span><br><span class="line">895</span><br><span class="line">896</span><br><span class="line">897</span><br><span class="line">898</span><br><span class="line">899</span><br><span class="line">900</span><br><span class="line">901</span><br><span class="line">902</span><br><span class="line">903</span><br><span class="line">904</span><br><span class="line">905</span><br><span class="line">906</span><br><span class="line">907</span><br><span class="line">908</span><br><span class="line">909</span><br><span class="line">910</span><br><span class="line">911</span><br><span class="line">912</span><br><span class="line">913</span><br><span class="line">914</span><br><span class="line">915</span><br><span class="line">916</span><br><span class="line">917</span><br><span class="line">918</span><br><span class="line">919</span><br><span class="line">920</span><br><span class="line">921</span><br><span class="line">922</span><br><span class="line">923</span><br><span class="line">924</span><br><span class="line">925</span><br><span class="line">926</span><br><span class="line">927</span><br><span class="line">928</span><br><span class="line">929</span><br><span class="line">930</span><br><span class="line">931</span><br><span class="line">932</span><br><span class="line">933</span><br><span class="line">934</span><br><span class="line">935</span><br><span class="line">936</span><br><span class="line">937</span><br><span class="line">938</span><br><span class="line">939</span><br><span class="line">940</span><br><span class="line">941</span><br><span class="line">942</span><br><span class="line">943</span><br><span class="line">944</span><br><span class="line">945</span><br><span class="line">946</span><br><span class="line">947</span><br><span class="line">948</span><br><span class="line">949</span><br><span class="line">950</span><br><span class="line">951</span><br><span class="line">952</span><br><span class="line">953</span><br><span class="line">954</span><br><span class="line">955</span><br><span class="line">956</span><br><span class="line">957</span><br><span class="line">958</span><br><span class="line">959</span><br><span class="line">960</span><br><span class="line">961</span><br><span class="line">962</span><br><span class="line">963</span><br><span class="line">964</span><br><span class="line">965</span><br><span class="line">966</span><br><span class="line">967</span><br><span class="line">968</span><br><span class="line">969</span><br><span class="line">970</span><br><span class="line">971</span><br><span class="line">972</span><br><span class="line">973</span><br><span class="line">974</span><br><span class="line">975</span><br><span class="line">976</span><br><span class="line">977</span><br><span class="line">978</span><br><span class="line">979</span><br><span class="line">980</span><br><span class="line">981</span><br><span class="line">982</span><br><span class="line">983</span><br><span class="line">984</span><br><span class="line">985</span><br><span class="line">986</span><br><span class="line">987</span><br><span class="line">988</span><br><span class="line">989</span><br><span class="line">990</span><br></pre></td><td class="code"><pre><span class="line"><span class="string">一、前言</span></span><br><span class="line"></span><br><span class="line"><span class="string">如果觉得文章有用，请帮忙波哥分享转发！~</span></span><br><span class="line"><span class="string">Compose是一个用于定义和运行多容器Docker应用程序的工具。使用Compose，您可以使用YAML文件来配置应用程序的服务。然后，使用单个命令，您可以从配置中创建并启动所有服务。</span></span><br><span class="line"><span class="string">Compose可以.yml</span> <span class="string">或</span> <span class="string">.yaml</span> <span class="string">作为文件扩展名。</span></span><br><span class="line"><span class="string">Compose适用于所有环境：生产，登台，开发，测试以及CI工作流程。</span></span><br><span class="line"><span class="string">关于</span> <span class="string">docker</span> <span class="string">compose</span> <span class="string">技术可以查看官方文档</span> <span class="string">Docker</span> <span class="string">Compose</span></span><br><span class="line"> </span><br><span class="line"><span class="string">以下的内容是确立在已经下载好</span> <span class="string">Docker</span> <span class="string">以及</span> <span class="string">Docker</span> <span class="string">Compose，可参看</span> <span class="string">Docker</span> <span class="string">Compose</span> <span class="string">的官方安装教程</span> <span class="string">Install</span> <span class="string">Docker</span> <span class="string">Compose</span></span><br><span class="line"><span class="string">二、Docker</span> <span class="string">Compose</span> <span class="string">配置文件的构建参数说明</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.1</span> <span class="string">build</span></span><br><span class="line"><span class="string">服务除了可以基于指定的镜像，还可以基于一份</span> <span class="string">Dockerfile，在使用</span> <span class="string">up</span> <span class="string">启动之时执行构建任务，这个构建标签就是</span> <span class="string">build，它可以指定</span> <span class="string">Dockerfile</span> <span class="string">所在文件夹的路径。Compose</span> <span class="string">将会利用它自动构建这个镜像，然后使用这个镜像启动服务容器。</span></span><br><span class="line"><span class="string">build</span> <span class="string">可以指定为包含构建上下文路径的字符串：</span></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">webapp:</span></span><br><span class="line">    <span class="string">build:./dir</span></span><br><span class="line"><span class="string">或者，作为具有在上下文中指定的路径的对象以及可选的Dockerfile和args：</span></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">webapp:</span></span><br><span class="line">    <span class="attr">build:</span></span><br><span class="line">      <span class="string">context:./dir</span></span><br><span class="line">      <span class="string">dockerfile:Dockerfile-alternate</span></span><br><span class="line">      <span class="attr">args:</span></span><br><span class="line">        <span class="string">buildno:1</span></span><br><span class="line"><span class="string">如果您指定image以及build，则使用以下指定的webapp和可选项对构建的图像进行命名：</span></span><br><span class="line"><span class="string">这会在./dir目录下生成一个名为webapp和标记的图像tag。</span></span><br><span class="line"><span class="string">build:./dir</span></span><br><span class="line"><span class="string">image:webapp:tag</span></span><br><span class="line"><span class="string">注意:当用(Version</span> <span class="number">3</span><span class="string">)</span> <span class="string">Compose</span> <span class="string">文件在群集模式下部署堆栈时，该选项被忽略。因为</span> <span class="string">docker</span> <span class="string">stack</span> <span class="string">命令只接受预先构建的镜像。</span></span><br><span class="line"><span class="number">2.2</span> <span class="string">context</span></span><br><span class="line"><span class="string">context</span> <span class="string">选项可以是</span> <span class="string">Dockerfile</span> <span class="string">的文件路径，也可以是到链接到</span> <span class="string">git</span> <span class="string">仓库的</span> <span class="string">url。</span></span><br><span class="line"><span class="string">当提供的值是相对路径时，它被解析为相对于撰写文件的路径，此目录也是发送到</span> <span class="string">Docker</span> <span class="string">守护进程的</span> <span class="string">context。</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:./dir</span></span><br><span class="line"><span class="number">2.3</span> <span class="string">dockerfile</span></span><br><span class="line"><span class="string">使用此</span> <span class="string">dockerfile</span> <span class="string">文件来构建，必须指定构建路径。</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="string">dockerfile:Dockerfile-alternate</span></span><br><span class="line"><span class="number">2.4</span> <span class="string">args</span></span><br><span class="line"><span class="string">添加构建参数，这些参数是仅在构建过程中可访问的环境变量。</span></span><br><span class="line"><span class="string">首先，在Dockerfile中指定参数：</span></span><br><span class="line"><span class="string">ARG</span> <span class="string">buildno</span></span><br><span class="line"><span class="string">ARG</span> <span class="string">gitcommithash</span></span><br><span class="line"> </span><br><span class="line"><span class="string">RUN</span> <span class="string">echo</span> <span class="string">&quot;Build number: $buildno&quot;</span></span><br><span class="line"><span class="string">RUN</span> <span class="string">echo</span> <span class="string">&quot;Based on commit: $gitcommithash&quot;</span></span><br><span class="line"><span class="string">然后在build键下指定参数，可以传递映射或列表：</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="attr">args:</span></span><br><span class="line">    <span class="string">buildno:1</span></span><br><span class="line">    <span class="string">gitcommithash:cdc3b19</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="attr">args:</span></span><br><span class="line">    <span class="string">-buildno=1</span></span><br><span class="line">    <span class="string">-gitcommithash=cdc3b19</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：在Dockerfile中，如果ARG在FROM指令之前指定，</span> <span class="string">ARG则在构建说明中不可用FROM。如果您需要在两个位置都可以使用参数，请在FROM指令下指定它。</span></span><br><span class="line"><span class="string">您可以在指定构建参数时省略该值，在这种情况下，它在构建时的值是运行Compose的环境中的值。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">args:</span></span><br><span class="line">  <span class="string">-buildno</span></span><br><span class="line">  <span class="string">-gitcommithash</span></span><br><span class="line"><span class="string">注意：YAML布尔值（true，false，yes，no，on，off）必须用引号括起来，这样分析器会将它们解释为字符串。</span></span><br><span class="line"><span class="number">2.5</span> <span class="string">cache_from</span></span><br><span class="line"><span class="string">编写缓存解析镜像列表，此选项是v3.2中的新选项。</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="attr">cache_from:</span></span><br><span class="line">    <span class="string">-alpine:latest</span></span><br><span class="line">    <span class="string">-corp/web_app:3.14</span></span><br><span class="line"><span class="number">2.6</span> <span class="string">labels</span></span><br><span class="line"><span class="string">使用</span> <span class="string">Docker标签</span> <span class="string">将元数据添加到生成的镜像中，可以使用数组或字典。</span></span><br><span class="line"><span class="string">建议使用反向</span> <span class="string">DNS</span> <span class="string">标记来防止签名与其他软件所使用的签名冲突，此选项是v3.3中的新选项。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="attr">labels:</span></span><br><span class="line">    <span class="string">com.example.description:&quot;Accountingwebapp&quot;</span></span><br><span class="line">    <span class="string">com.example.department:&quot;Finance&quot;</span></span><br><span class="line">    <span class="string">com.example.label-with-empty-value:&quot;&quot;</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="attr">labels:</span></span><br><span class="line">    <span class="string">-&quot;com.example.description=Accountingwebapp&quot;</span></span><br><span class="line">    <span class="string">-&quot;com.example.department=Finance&quot;</span></span><br><span class="line">    <span class="string">-&quot;com.example.label-with-empty-value&quot;</span></span><br><span class="line"><span class="number">2.7</span> <span class="string">shm_size</span></span><br><span class="line"><span class="string">设置容器</span> <span class="string">/dev/shm</span> <span class="string">分区的大小，值为表示字节的整数值或表示字符的字符串</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="string">shm_size:&#x27;2gb&#x27;</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="string">shm_size:10000000</span></span><br><span class="line"><span class="number">2.8</span> <span class="string">target</span></span><br><span class="line"><span class="string">根据对应的</span> <span class="string">Dockerfile</span> <span class="string">构建指定</span> <span class="string">Stage</span></span><br><span class="line"><span class="attr">build:</span></span><br><span class="line">  <span class="string">context:.</span></span><br><span class="line">  <span class="string">target:prod</span></span><br><span class="line"><span class="number">2.9</span> <span class="string">cap_add，cap_drop</span></span><br><span class="line"><span class="string">添加或删除容器功能，可查看</span> <span class="string">man</span> <span class="number">7</span> <span class="string">capabilities</span></span><br><span class="line"><span class="attr">cap_add:</span></span><br><span class="line">  <span class="string">-ALL</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">cap_drop:</span></span><br><span class="line">  <span class="string">-NET_ADMIN</span></span><br><span class="line">  <span class="string">-SYS_ADMIN</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意:当用(Version</span> <span class="number">3</span><span class="string">)</span> <span class="string">Compose</span> <span class="string">文件在群集模式下部署堆栈时，该选项被忽略。因为</span> <span class="string">docker</span> <span class="string">stack</span> <span class="string">命令只接受预先构建的镜像</span></span><br><span class="line"><span class="number">2.10</span> <span class="string">cgroup_parent</span></span><br><span class="line"><span class="string">可以为容器选择一个可选的父</span> <span class="string">cgroup_parent</span></span><br><span class="line"><span class="string">cgroup_parent:m-executor-abcd</span></span><br><span class="line"><span class="string">注意：当</span> <span class="string">使用（Version</span> <span class="number">3</span><span class="string">）Compose</span> <span class="string">文件在群集模式下部署堆栈时，忽略此选项</span></span><br><span class="line"><span class="number">2.11</span><span class="string">.</span> <span class="string">command</span></span><br><span class="line"><span class="string">覆盖容器启动后默认执行的命令</span></span><br><span class="line"><span class="string">command:bundle</span> <span class="string">exec</span> <span class="string">thin</span> <span class="string">-p</span> <span class="number">3000</span></span><br><span class="line"><span class="string">该命令也可以是一个列表，方式类似于dockerfile：</span></span><br><span class="line"><span class="string">command:[&quot;bundle&quot;,&quot;exec&quot;,&quot;thin&quot;,&quot;-p&quot;,&quot;3000&quot;]</span></span><br><span class="line"><span class="number">2.12</span><span class="string">.</span> <span class="string">configs</span></span><br><span class="line"><span class="string">使用服务</span> <span class="string">configs</span> <span class="string">配置为每个服务赋予相应的访问权限，支持两种不同的语法</span></span><br><span class="line"><span class="attr">Note:</span> <span class="string">配置必须存在或在</span> <span class="string">configs</span> <span class="string">此堆栈文件的顶层中定义，否则堆栈部署失效</span></span><br><span class="line"><span class="number">2.12</span><span class="number">.1</span> <span class="string">SHORT</span> <span class="string">语法</span></span><br><span class="line"><span class="string">SHORT</span> <span class="string">语法只能指定配置名称，这允许容器访问配置并将其安装在</span> <span class="string">/&lt;config_name&gt;</span> <span class="string">容器内，源名称和目标装入点都设为配置名称。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:latest</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:1</span></span><br><span class="line">    <span class="attr">configs:</span></span><br><span class="line">      <span class="string">-my_config</span></span><br><span class="line">      <span class="string">-my_other_config</span></span><br><span class="line"><span class="attr">configs:</span></span><br><span class="line">  <span class="attr">my_config:</span></span><br><span class="line">    <span class="string">file:./my_config.txt</span></span><br><span class="line">  <span class="attr">my_other_config:</span></span><br><span class="line">    <span class="string">external:true</span></span><br><span class="line"></span><br><span class="line"><span class="string">以上实例使用</span> <span class="string">SHORT</span> <span class="string">语法将</span> <span class="string">redis</span> <span class="string">服务访问授予</span> <span class="string">my_config</span> <span class="string">和</span> <span class="string">my_other_config</span> <span class="string">,并被</span> <span class="string">my_other_config</span> <span class="string">定义为外部资源，这意味着它已经在</span> <span class="string">Docker</span> <span class="string">中定义。可以通过</span> <span class="string">docker</span> <span class="string">config</span> <span class="string">create</span> <span class="string">命令或通过另一个堆栈部署。如果外部部署配置都不存在，则堆栈部署会失败并出现</span> <span class="string">config</span> <span class="string">not</span> <span class="string">found</span> <span class="string">错误。</span></span><br><span class="line"><span class="string">注意:</span> <span class="string">config</span> <span class="string">定义仅在</span> <span class="number">3.3</span> <span class="string">版本或在更高版本的撰写文件格式中受支持，YAML</span> <span class="string">的布尔值（true,</span> <span class="literal">false</span><span class="string">,</span> <span class="literal">yes</span><span class="string">,</span> <span class="literal">no</span><span class="string">,</span> <span class="string">on,</span> <span class="string">off）必须要使用引号引起来（单引号、双引号均可），否则会当成字符串解析。</span></span><br><span class="line"><span class="number">2.12</span><span class="number">.2</span> <span class="string">LONG</span> <span class="string">语法</span></span><br><span class="line"><span class="string">LONG</span> <span class="string">语法提供了创建服务配置的更加详细的信息。</span></span><br><span class="line"><span class="string">source：Docker</span> <span class="string">中存在的配置的名称</span></span><br><span class="line"><span class="string">target：要在服务的任务中装载的文件的路径或名称。如果未指定则默认为</span> <span class="string">/&lt;source&gt;</span> </span><br><span class="line"><span class="string">uid</span> <span class="string">和</span> <span class="string">gid：在服务的任务容器中拥有安装的配置文件的数字</span> <span class="string">UID</span> <span class="string">或</span> <span class="string">GID。如果未指定，则默认为在Linux上。Windows不支持。</span></span><br><span class="line"><span class="string">mode：在服务的任务容器中安装的文件的权限，以八进制表示法。例如，0444</span> <span class="string">代表文件可读的。默认是</span> <span class="number">0444</span><span class="string">。如果配置文件无法写入，是因为它们安装在临时文件系统中，所以如果设置了可写位，它将被忽略。可执行位可以设置。如果您不熟悉</span> <span class="string">UNIX</span> <span class="string">文件权限模式，Unix</span> <span class="string">Permissions</span> <span class="string">Calculator</span></span><br><span class="line"> </span><br><span class="line"><span class="string">下面示例在容器中将</span> <span class="string">my_config</span> <span class="string">名称设置为</span> <span class="string">redis_config，将模式设置为</span> <span class="number">0440</span><span class="string">（group-readable）并将用户和组设置为</span> <span class="number">103</span><span class="string">。该redis服务无法访问</span> <span class="string">my_other_config</span> <span class="string">配置。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:latest</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:1</span></span><br><span class="line">    <span class="attr">configs:</span></span><br><span class="line">      <span class="string">-source:my_config</span></span><br><span class="line">        <span class="string">target:/redis_config</span></span><br><span class="line">        <span class="string">uid:&#x27;103&#x27;</span></span><br><span class="line">        <span class="string">gid:&#x27;103&#x27;</span></span><br><span class="line">        <span class="string">mode:0440</span></span><br><span class="line"><span class="attr">configs:</span></span><br><span class="line">  <span class="attr">my_config:</span></span><br><span class="line">    <span class="string">file:./my_config.txt</span></span><br><span class="line">  <span class="attr">my_other_config:</span></span><br><span class="line">    <span class="string">external:true</span></span><br><span class="line"></span><br><span class="line"><span class="string">可以同时授予多个配置的服务相应的访问权限，也可以混合使用</span> <span class="string">LONG</span> <span class="string">和</span> <span class="string">SHORT</span> <span class="string">语法。定义配置并不意味着授予服务访问权限。</span></span><br><span class="line"><span class="number">2.13</span> <span class="string">container_name</span></span><br><span class="line"><span class="string">为自定义的容器指定一个名称，而不是使用默认的名称</span></span><br><span class="line"><span class="string">container_name:my-web-container</span></span><br><span class="line"><span class="string">由于Docker容器名称必须是唯一的，因此如果指定了自定义名称，则无法将服务扩展到1个容器之外。试图这样做会导致错误。</span></span><br><span class="line"><span class="string">注意：使用（版本3）Compose文件在群集模式下部署堆栈时，将忽略此选项</span> <span class="string">。</span></span><br><span class="line"><span class="number">2.14</span> <span class="string">credential_spec</span></span><br><span class="line"><span class="string">注意：此选项已在v3.3中添加。在Compose版本3.8中支持使用具有撰写文件的组托管服务帐户（GMSA）配置。</span></span><br><span class="line"><span class="string">配置托管服务帐户的凭据规范。此选项仅用于使用Windows容器的服务。</span></span><br><span class="line"><span class="string">使用</span> <span class="string">file时:</span> <span class="string">应该注意引用的文件必须存在于CredentialSpecs,docker</span> <span class="string">数据目录的子目录中。在</span> <span class="string">Windows</span> <span class="string">上，该目录默认为</span> <span class="string">C:\ProgramData\Docker\。以下示例从名为C:\ProgramData\Docker\CredentialSpecs\my-credential-spec.json</span> <span class="string">的文件加载凭证规范</span> <span class="string">：</span></span><br><span class="line"><span class="attr">credential_spec:</span></span><br><span class="line">  <span class="string">file:my-credential-spec.json</span></span><br><span class="line"><span class="string">使用</span> <span class="attr">registry:</span> <span class="string">将从守护进程主机上的</span> <span class="string">Windows</span> <span class="string">注册表中读取凭据规范。其注册表值必须位于：</span></span><br><span class="line"><span class="string">HKLM\SOFTWARE\Microsoft\Windows</span> <span class="string">NT\CurrentVersion\Virtualization\Containers\CredentialSpecs</span></span><br><span class="line"><span class="string">下面的示例通过</span> <span class="string">my-credential-spec</span> <span class="string">注册表中指定的值加载凭证规范：</span></span><br><span class="line"><span class="attr">credential_spec:</span></span><br><span class="line">  <span class="string">registry:my-credential-spec</span></span><br><span class="line"><span class="string">示例GMSA配置</span></span><br><span class="line"><span class="string">为服务配置GMSA凭据规范时，只需指定凭据规范config，如以下示例所示：</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.8&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">myservice:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">myimage:latest</span></span><br><span class="line">    <span class="attr">credential_spec:</span></span><br><span class="line">      <span class="attr">config:</span> <span class="string">my_credential_spec</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">configs:</span></span><br><span class="line">  <span class="attr">my_credentials_spec:</span></span><br><span class="line">    <span class="attr">file:</span> <span class="string">./my-credential-spec.json|</span></span><br><span class="line"><span class="number">2.15</span> <span class="string">depends_on</span></span><br><span class="line"><span class="string">容器中服务之间的依赖关系，依赖关系会导致以下行为：</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">up以依赖顺序启动服务。在以下示例中，db并redis在之前启动web。</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">up</span> <span class="string">SERVICE自动包含SERVICE依赖项。在以下示例中，docker-compose</span> <span class="string">up</span> <span class="string">web还创建并启动db和redis。</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">stop按依赖顺序停止服务。在以下示例中，web在db和之前停止redis</span></span><br><span class="line"> </span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="string">build:.</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="string">-db</span></span><br><span class="line">      <span class="string">-redis</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis</span></span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="string">image:postgres</span></span><br><span class="line"></span><br><span class="line"><span class="string">使用时需要注意以下几点depends_on：</span></span><br><span class="line"><span class="string">depends_on不会在启动web之前等待db和redis“就绪”</span></span><br><span class="line"><span class="string">版本3不再支持condition形式depends_on。</span></span><br><span class="line"><span class="string">使用版本3</span> <span class="string">Compose文件在swarm模式下部署堆栈depends_on时，将忽略该选项</span> <span class="string">。</span></span><br><span class="line"><span class="number">2.16</span> <span class="string">deploy</span></span><br><span class="line"><span class="string">指定与部署和运行服务相关的配置。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:alpine</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:6</span></span><br><span class="line">      <span class="attr">update_config:</span></span><br><span class="line">        <span class="string">parallelism:2</span></span><br><span class="line">        <span class="string">delay:10s</span></span><br><span class="line">      <span class="attr">restart_policy:</span></span><br><span class="line">        <span class="string">condition:on-failure</span></span><br><span class="line"></span><br><span class="line"><span class="string">有几个子选项可供选择：</span></span><br><span class="line"><span class="number">2.16</span><span class="number">.1</span> <span class="string">endpoint_mode</span></span><br><span class="line"><span class="string">endpoint_mode：指定连接到群组外部客户端服务发现方法</span></span><br><span class="line"><span class="string">endpoint_mode:vip</span> <span class="string">：Docker</span> <span class="string">为该服务分配了一个虚拟</span> <span class="string">IP(VIP),作为客户端的</span>  <span class="string">“前端“</span> <span class="string">部位用于访问网络上的服务。</span></span><br><span class="line"><span class="attr">endpoint_mode: dnsrr :</span> <span class="string">DNS轮询（DNSRR）服务发现不使用单个虚拟</span> <span class="string">IP。Docker为服务设置</span> <span class="string">DNS</span> <span class="string">条目，使得服务名称的</span> <span class="string">DNS</span> <span class="string">查询返回一个</span> <span class="string">IP</span> <span class="string">地址列表，并且客户端直接连接到其中的一个。如果想使用自己的负载平衡器，或者混合</span> <span class="string">Windows</span> <span class="string">和</span> <span class="string">Linux</span> <span class="string">应用程序，则</span> <span class="string">DNS</span> <span class="string">轮询调度（round-robin）功能就非常实用。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">wordpress:</span></span><br><span class="line">    <span class="string">image:wordpress</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="string">-&quot;8080:80&quot;</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="string">-overlay</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">mode:replicated</span></span><br><span class="line">      <span class="string">replicas:2</span></span><br><span class="line">      <span class="string">endpoint_mode:vip</span></span><br><span class="line"> </span><br><span class="line">  <span class="attr">mysql:</span></span><br><span class="line">    <span class="string">image:mysql</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">       <span class="string">-db-data:/var/lib/mysql/data</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">       <span class="string">-overlay</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">mode:replicated</span></span><br><span class="line">      <span class="string">replicas:2</span></span><br><span class="line">      <span class="string">endpoint_mode:dnsrr</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">db-data:</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">overlay:</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.2</span> <span class="string">labels</span></span><br><span class="line"><span class="string">指定服务的标签，这些标签仅在服务上设置</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="string">image:web</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="attr">labels:</span></span><br><span class="line">        <span class="string">com.example.description:&quot;Thislabelwillappearonthewebservice&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">通过将</span> <span class="string">deploy</span> <span class="string">外面的</span> <span class="string">labels</span> <span class="string">标签来设置容器上的</span> <span class="string">labels</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="string">image:web</span></span><br><span class="line">    <span class="attr">labels:</span></span><br><span class="line">      <span class="string">com.example.description:&quot;Thislabelwillappearonallcontainersforthewebservice&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.3</span> <span class="string">mode</span></span><br><span class="line"><span class="string">global:每个集节点只有一个容器</span></span><br><span class="line"><span class="string">replicated:指定容器数量（默认）</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">worker:</span></span><br><span class="line">    <span class="string">image:dockersamples/examplevotingapp_worker</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">mode:global</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.4</span> <span class="string">placement</span></span><br><span class="line"><span class="string">指定</span> <span class="string">constraints</span> <span class="string">和</span> <span class="string">preferences</span> </span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="string">image:postgres</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="attr">placement:</span></span><br><span class="line">        <span class="attr">constraints:</span></span><br><span class="line">          <span class="string">-node.role</span> <span class="string">==</span> <span class="string">manager</span></span><br><span class="line">          <span class="string">-engine.labels.operatingsystem</span> <span class="string">==</span> <span class="string">ubuntu</span> <span class="number">14.04</span></span><br><span class="line">        <span class="attr">preferences:</span></span><br><span class="line">          <span class="string">-spread:node.labels.zone</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.5</span> <span class="string">replicas</span></span><br><span class="line"><span class="string">如果服务是</span> <span class="string">replicated（默认)，需要指定运行的容器数量</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">worker:</span></span><br><span class="line">    <span class="string">image:dockersamples/examplevotingapp_worker</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="string">-frontend</span></span><br><span class="line">      <span class="string">-backend</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">mode:replicated</span></span><br><span class="line">      <span class="string">replicas:6</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.6</span>  <span class="string">resources</span></span><br><span class="line"><span class="string">配置资源限制</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:alpine</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="attr">resources:</span></span><br><span class="line">        <span class="attr">limits:</span></span><br><span class="line">          <span class="string">cpus:&#x27;0.50&#x27;</span></span><br><span class="line">          <span class="string">memory:50M</span></span><br><span class="line">        <span class="attr">reservations:</span></span><br><span class="line">          <span class="string">cpus:&#x27;0.25&#x27;</span></span><br><span class="line">          <span class="string">memory:20M</span></span><br><span class="line"></span><br><span class="line"><span class="string">此例子中，redis</span> <span class="string">服务限制使用不超过</span> <span class="string">50M</span> <span class="string">的内存和</span> <span class="number">0.50</span><span class="string">（50％）可用处理时间（CPU），并且保留</span> <span class="string">20M</span> <span class="string">了内存和</span> <span class="number">0.25</span> <span class="string">CPU时间。</span></span><br><span class="line"><span class="number">2.16</span><span class="number">.7</span> <span class="string">restart_policy</span></span><br><span class="line"><span class="string">配置容器的重新启动，代替</span> <span class="string">restart</span></span><br><span class="line"><span class="string">condition：值可以为</span> <span class="string">none</span> <span class="string">、on-failure</span> <span class="string">以及</span> <span class="string">any(默认)</span></span><br><span class="line"><span class="string">delay：尝试重启的等待时间，默认为</span> <span class="number">0</span></span><br><span class="line"><span class="string">max_attempts：在放弃之前尝试重新启动容器次数（默认：从不放弃）。如果重新启动在配置中没有成功</span> <span class="string">window，则此尝试不计入配置max_attempts</span> <span class="string">值。例如，如果</span> <span class="string">max_attempts</span> <span class="string">值为</span> <span class="number">2</span><span class="string">，并且第一次尝试重新启动失败，则可能会尝试重新启动两次以上。</span></span><br><span class="line"><span class="string">windows：在决定重新启动是否成功之前的等时间，指定为持续时间（默认值：立即决定）。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:alpine</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="attr">restart_policy:</span></span><br><span class="line">        <span class="string">condition:on-failure</span></span><br><span class="line">        <span class="string">delay:5s</span></span><br><span class="line">        <span class="string">max_attempts:3</span></span><br><span class="line">        <span class="string">window:120s</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.16</span><span class="number">.8</span> <span class="string">rollback_config</span></span><br><span class="line"><span class="string">配置在更新失败的情况下应如何回滚服务。</span></span><br><span class="line"><span class="string">parallelism：一次回滚的容器数。如果设置为0，则所有容器同时回滚。</span></span><br><span class="line"><span class="string">delay：每个容器组的回滚之间等待的时间（默认为0）。</span></span><br><span class="line"><span class="string">failure_action：如果回滚失败该怎么办。一个continue或pause（默认pause）</span></span><br><span class="line"><span class="string">monitor：每次更新任务后的持续时间以监视失败(ns|us|ms|s|m|h)（默认为0）。</span></span><br><span class="line"><span class="string">max_failure_ratio：回滚期间容忍的失败率（默认为0）。</span></span><br><span class="line"><span class="string">order：回滚期间的操作顺序。其中一个stop-first（旧任务在启动新任务之前停止），或者start-first（首先启动新任务，并且正在运行的任务暂时重叠）（默认stop-first）。</span></span><br><span class="line"><span class="number">2.16</span><span class="number">.9</span> <span class="string">update_config</span></span><br><span class="line"><span class="string">配置更新服务，用于无缝更新应用（rolling</span> <span class="string">update)</span></span><br><span class="line"><span class="string">parallelism：一次性更新的容器数量</span></span><br><span class="line"><span class="string">delay：更新一组容器之间的等待时间。</span></span><br><span class="line"><span class="string">failure_action：如果更新失败，可以执行的的是</span> <span class="string">continue、rollback</span> <span class="string">或</span> <span class="string">pause</span> <span class="string">（默认）</span></span><br><span class="line"><span class="string">monitor：每次任务更新后监视失败的时间(ns|us|ms|s|m|h)（默认为0）</span></span><br><span class="line"><span class="string">max_failure_ratio：在更新期间能接受的失败率</span></span><br><span class="line"><span class="string">order：更新次序设置，top-first（旧的任务在开始新任务之前停止）、start-first（新的任务首先启动，并且正在运行的任务短暂重叠）（默认</span> <span class="string">stop-first）</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">vote:</span></span><br><span class="line">    <span class="string">image:dockersamples/examplevotingapp_vote:before</span></span><br><span class="line">    <span class="attr">depends_on:</span></span><br><span class="line">      <span class="string">-redis</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:2</span></span><br><span class="line">      <span class="attr">update_config:</span></span><br><span class="line">        <span class="string">parallelism:2</span></span><br><span class="line">        <span class="string">delay:10s</span></span><br><span class="line">        <span class="string">order:stop-first</span></span><br><span class="line"></span><br><span class="line"><span class="string">不支持</span> <span class="string">Docker</span> <span class="string">stack</span> <span class="string">desploy</span> <span class="string">的几个子选项</span> </span><br><span class="line"><span class="string">build、cgroup_parent、container_name、devices、tmpfs、external_links、inks、network_mode、restart、security_opt、stop_signal、sysctls、userns_mode</span></span><br><span class="line"><span class="number">2.17</span> <span class="string">devices</span></span><br><span class="line"><span class="string">设置映射列表，与</span> <span class="string">Docker</span> <span class="string">客户端的</span> <span class="string">--device</span> <span class="string">参数类似</span></span><br><span class="line"></span><br><span class="line"><span class="attr">devices:</span></span><br><span class="line">  <span class="string">-&quot;/dev/ttyUSB0:/dev/ttyUSB0&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.18</span> <span class="string">dns</span></span><br><span class="line"><span class="string">自定义</span> <span class="string">DNS</span> <span class="string">服务器，与</span> <span class="string">--dns</span> <span class="string">具有一样的用途，可以是单个值或列表</span></span><br><span class="line"></span><br><span class="line"><span class="string">dns:8.8.8.8</span></span><br><span class="line"><span class="attr">dns:</span></span><br><span class="line">  <span class="number">-8.8</span><span class="number">.8</span><span class="number">.8</span></span><br><span class="line">  <span class="number">-9.9</span><span class="number">.9</span><span class="number">.9</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.19</span> <span class="string">dns_search</span></span><br><span class="line"><span class="string">自定义</span> <span class="string">DNS</span> <span class="string">搜索域，可以是单个值或列表</span></span><br><span class="line"></span><br><span class="line"><span class="string">dns_search:example.com</span></span><br><span class="line"><span class="attr">dns_search:</span></span><br><span class="line">  <span class="string">-dc1.example.com</span></span><br><span class="line">  <span class="string">-dc2.example.com</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.20</span> <span class="string">entrypoint</span></span><br><span class="line"><span class="string">在</span> <span class="string">Dockerfile</span> <span class="string">中有一个指令叫做</span> <span class="string">ENTRYPOINT</span> <span class="string">指令，用于指定接入点。在</span> <span class="string">docker-compose.yml</span> <span class="string">中可以定义接入点，覆盖</span> <span class="string">Dockerfile</span> <span class="string">中的定义</span></span><br><span class="line"></span><br><span class="line"><span class="string">entrypoint:/code/entrypoint.sh</span></span><br><span class="line"><span class="string">入口点也可以是一个列表，方式类似于</span> <span class="string">dckerfile：</span></span><br><span class="line"><span class="attr">entrypoint:</span></span><br><span class="line">    <span class="string">-php</span></span><br><span class="line">    <span class="string">--d</span></span><br><span class="line">    <span class="string">-zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so</span></span><br><span class="line">    <span class="string">--d</span></span><br><span class="line">    <span class="string">-memory_limit=-1</span></span><br><span class="line">    <span class="string">-vendor/bin/phpunit</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.21</span> <span class="string">env_file</span></span><br><span class="line"><span class="string">从文件中添加环境变量。可以是单个值或是列表</span> </span><br><span class="line"><span class="string">如果已经用</span> <span class="string">docker-compose</span> <span class="string">-f</span> <span class="string">FILE</span> <span class="string">指定了</span> <span class="string">Compose</span> <span class="string">文件，那么</span> <span class="string">env_file</span> <span class="string">路径值为相对于该文件所在的目录</span></span><br><span class="line"><span class="string">但</span> <span class="string">environment</span> <span class="string">环境中的设置的变量会会覆盖这些值，无论这些值未定义还是为</span> <span class="string">None</span></span><br><span class="line"><span class="string">env_file:.env</span></span><br><span class="line"><span class="attr">env_file:</span></span><br><span class="line">  <span class="string">-./common.env</span></span><br><span class="line">  <span class="string">-./apps/web.env</span></span><br><span class="line">  <span class="string">-/opt/secrets.env</span></span><br><span class="line"><span class="string">环境配置文件</span> <span class="string">env_file</span> <span class="string">中的声明每行都是以</span> <span class="string">VAR=VAL</span> <span class="string">格式，其中以</span> <span class="comment"># 开头的被解析为注释而被忽略，注意环境变量配置列表的顺序，例如下面例子</span></span><br><span class="line"></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">some-service:</span></span><br><span class="line">    <span class="attr">env_file:</span></span><br><span class="line">      <span class="string">-a.env</span></span><br><span class="line">      <span class="string">-b.env</span></span><br><span class="line"><span class="string">a.env</span> <span class="string">文件</span></span><br><span class="line"><span class="comment"># a.env</span></span><br><span class="line"><span class="string">VAR=1</span></span><br><span class="line"><span class="string">b.env文件</span></span><br><span class="line"><span class="comment"># b.env</span></span><br><span class="line"><span class="string">VAR=hello</span></span><br><span class="line"></span><br><span class="line"><span class="string">对于在文件a.env</span> <span class="string">中指定的相同变量但在文件</span> <span class="string">b.env</span> <span class="string">中分配了不同的值，如果</span> <span class="string">b.env</span> <span class="string">像下面列在</span> <span class="string">a.env</span> <span class="string">之后，则刚在</span> <span class="string">a.env</span> <span class="string">设置的值被</span> <span class="string">b.env</span> <span class="string">相同变量的值覆盖，此时</span> <span class="string">$VAR</span> <span class="string">值为</span> <span class="string">hello。此外，这里所说的环境变量是对宿主机的</span> <span class="string">Compose</span> <span class="string">而言的，如果在配置文件中有</span> <span class="string">build</span> <span class="string">操作，这些变量并不会进入构建过程中，如果要在构建中使用变量还是首选</span> <span class="string">arg</span> <span class="string">标签。</span></span><br><span class="line"><span class="number">2.22</span> <span class="string">environment</span></span><br><span class="line"><span class="string">添加环境变量，可以使用数组或字典。与上面的</span> <span class="string">env_file</span> <span class="string">选项完全不同，反而和</span> <span class="string">arg</span> <span class="string">有几分类似，这个标签的作用是设置镜像变量，它可以保存变量到镜像里面，也就是说启动的容器也会包含这些变量设置，这是与</span> <span class="string">arg</span> <span class="string">最大的不同。</span> </span><br><span class="line"><span class="string">一般</span> <span class="string">arg</span> <span class="string">标签的变量仅用在构建过程中。而</span> <span class="string">environment</span> <span class="string">和</span> <span class="string">Dockerfile</span> <span class="string">中的</span> <span class="string">ENV</span> <span class="string">指令一样会把变量一直保存在镜像、容器中，类似</span> <span class="string">docker</span> <span class="string">run</span> <span class="string">-e</span> <span class="string">的效果。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">environment:</span></span><br><span class="line">  <span class="string">RACK_ENV:development</span></span><br><span class="line">  <span class="string">SHOW:&#x27;true&#x27;</span></span><br><span class="line">  <span class="attr">SESSION_SECRET:</span></span><br><span class="line"><span class="attr">environment:</span></span><br><span class="line">  <span class="string">-RACK_ENV=development</span></span><br><span class="line">  <span class="string">-SHOW=true</span></span><br><span class="line">  <span class="string">-SESSION_SECRET</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.23</span> <span class="string">expose</span></span><br><span class="line"><span class="string">暴露端口，但不映射到宿主机，只被连接的服务访问。这个标签与</span> <span class="string">Dockerfile</span> <span class="string">中的</span> <span class="string">EXPOSE</span> <span class="string">指令一样，用于指定暴露的端口，但是只是作为一种参考，实际上</span> <span class="string">docker-compose.yml</span> <span class="string">的端口映射还得</span> <span class="string">ports</span> <span class="string">这样的标签</span></span><br><span class="line"></span><br><span class="line"><span class="attr">expose:</span></span><br><span class="line"> <span class="string">-&quot;3000&quot;</span></span><br><span class="line"> <span class="string">-&quot;8000&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.24</span> <span class="string">external_links</span></span><br><span class="line"><span class="string">链接到</span> <span class="string">docker-compose.yml</span> <span class="string">外部的容器，甚至并非</span> <span class="string">Compose</span> <span class="string">项目文件管理的容器。参数格式跟</span> <span class="string">links</span> <span class="string">类似。</span></span><br><span class="line"><span class="string">在使用Docker过程中，会有许多单独使用</span> <span class="string">docker</span> <span class="string">run</span> <span class="string">启动的容器的情况，为了使</span> <span class="string">Compose</span> <span class="string">能够连接这些不在docker-compose.yml</span> <span class="string">配置文件中定义的容器，那么就需要一个特殊的标签，就是</span> <span class="string">external_links，它可以让Compose</span> <span class="string">项目里面的容器连接到那些项目配置外部的容器（前提是外部容器中必须至少有一个容器是连接到与项目内的服务的同一个网络里面）。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">external_links:</span></span><br><span class="line"> <span class="string">-redis_1</span></span><br><span class="line"> <span class="string">-project_db_1:mysql</span></span><br><span class="line"> <span class="string">-project_db_1:postgresql</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.25</span> <span class="string">extra_hosts</span></span><br><span class="line"><span class="string">添加主机名的标签，就是往</span> <span class="string">/etc/hosts</span> <span class="string">文件中添加一些记录，与</span> <span class="string">Docker</span> <span class="string">客户端中的</span> <span class="string">--add-host</span> <span class="string">类似。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">extra_hosts:</span></span><br><span class="line"> <span class="string">-&quot;somehost:162.242.195.82&quot;</span></span><br><span class="line"> <span class="string">-&quot;otherhost:50.31.209.229&quot;</span></span><br><span class="line"><span class="string">在/etc/hosts此服务的内部容器中创建具有ip地址和主机名的条目，例如：</span></span><br><span class="line"><span class="number">162.242</span><span class="number">.195</span><span class="number">.82</span>  <span class="string">somehost</span></span><br><span class="line"><span class="number">50.31</span><span class="number">.209</span><span class="number">.229</span>   <span class="string">otherhost</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.26</span> <span class="string">healthcheck</span></span><br><span class="line"><span class="string">用于检查测试服务使用的容器是否正常</span></span><br><span class="line"></span><br><span class="line"><span class="attr">healthcheck:</span></span><br><span class="line">  <span class="string">test:[&quot;CMD&quot;,&quot;curl&quot;,&quot;-f&quot;,&quot;http://localhost&quot;]</span></span><br><span class="line">  <span class="string">interval:1m30s</span></span><br><span class="line">  <span class="string">timeout:10s</span></span><br><span class="line">  <span class="string">retries:3</span></span><br><span class="line">  <span class="string">start_period:40s</span></span><br><span class="line"></span><br><span class="line"><span class="string">interval，timeout</span> <span class="string">以及</span> <span class="string">start_period</span> <span class="string">都定为持续时间</span></span><br><span class="line"><span class="string">test</span> <span class="string">必须是字符串或列表，如果它是一个列表，第一项必须是</span> <span class="string">NONE，CMD</span> <span class="string">或</span> <span class="string">CMD-SHELL</span> <span class="string">；如果它是一个字符串，则相当于指定CMD-SHELL</span> <span class="string">后跟该字符串。</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># Hit the local web app</span></span><br><span class="line"><span class="string">test:[&quot;CMD&quot;,&quot;curl&quot;,&quot;-f&quot;,&quot;http://localhost&quot;]</span></span><br><span class="line"><span class="string">如上所述，但包裹在内/bin/sh。以下两种形式都是等同的。</span></span><br><span class="line"><span class="string">test:[&quot;CMD-SHELL&quot;,&quot;curl-fhttp://localhost||exit1&quot;]</span></span><br><span class="line"><span class="string">test:curl</span> <span class="string">-f</span> <span class="string">https://localhost</span> <span class="string">||</span> <span class="string">exit</span> <span class="number">1</span></span><br><span class="line"></span><br><span class="line"><span class="string">果需要禁用镜像的所有检查项目，可以使用</span> <span class="string">disable:true,相当于</span> <span class="string">test:[&quot;NONE&quot;]</span></span><br><span class="line"></span><br><span class="line"><span class="attr">healthcheck:</span></span><br><span class="line">  <span class="string">disable:true</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.27</span> <span class="string">image</span></span><br><span class="line"><span class="string">从指定的镜像中启动容器，可以是存储仓库、标签以及镜像</span> <span class="string">ID。</span></span><br><span class="line"><span class="string">如果镜像不存在，Compose</span> <span class="string">会自动拉去镜像。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">image:</span> <span class="string">redis</span></span><br><span class="line"><span class="attr">image:</span> <span class="string">ubuntu:14.04</span></span><br><span class="line"><span class="attr">image:</span> <span class="string">tutum/influxdb</span></span><br><span class="line"><span class="attr">image:</span> <span class="string">example-registry.com:4000/postgresql</span></span><br><span class="line"><span class="attr">image:</span> <span class="string">a4bc65fd</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.28</span> <span class="string">init</span></span><br><span class="line"><span class="string">在容器内运行init，转发信号并重新获得进程。将此选项设置true是为服务启用此功能。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="string">image:alpine:latest</span></span><br><span class="line">    <span class="string">init:true</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.29</span>  <span class="string">isolation</span></span><br><span class="line"><span class="string">指定容器的隔离技术。在Linux上，唯一支持的值是default。在Windows中，可接受的值是default，process和</span> <span class="string">hyperv。</span></span><br><span class="line"><span class="number">2.30</span> <span class="string">links</span></span><br><span class="line"><span class="string">链接到其它服务的中的容器，可以指定服务名称也可以指定链接别名（SERVICE：ALIAS)，与</span> <span class="string">Docker</span> <span class="string">客户端的</span> <span class="string">--link</span> <span class="string">有一样效果，会连接到其它服务中的容器。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">web:</span></span><br><span class="line">  <span class="attr">links:</span></span><br><span class="line">   <span class="string">-db</span></span><br><span class="line">   <span class="string">-db:database</span></span><br><span class="line">   <span class="string">-redis</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.31</span> <span class="string">logging</span></span><br><span class="line"><span class="string">配置日志服务</span></span><br><span class="line"></span><br><span class="line"><span class="attr">logging:</span></span><br><span class="line">  <span class="string">driver:syslog</span></span><br><span class="line">  <span class="attr">options:</span></span><br><span class="line">    <span class="string">syslog-address:&quot;tcp://192.168.0.42:123&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">该</span> <span class="string">driver值是指定服务器的日志记录驱动程序，默认值为</span> <span class="string">json-file,与</span> <span class="string">--log-diver</span> <span class="string">选项一样</span> </span><br><span class="line"></span><br><span class="line"><span class="attr">driver:</span> <span class="string">&quot;json-file&quot;</span></span><br><span class="line"><span class="attr">driver:</span> <span class="string">&quot;syslog&quot;</span></span><br><span class="line"><span class="attr">driver:</span> <span class="string">&quot;none&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：只有驱动程序</span> <span class="string">json-file</span> <span class="string">和</span> <span class="string">journald</span> <span class="string">驱动程序可以直接从</span> <span class="string">docker-compose</span> <span class="string">up</span> <span class="string">和</span> <span class="string">docker-compose</span> <span class="string">logs</span> <span class="string">获取日志。使用任何其他方式不会显示任何日志。</span></span><br><span class="line"><span class="string">对于可选值，可以使用</span> <span class="string">options</span> <span class="string">指定日志记录中的日志记录选项</span></span><br><span class="line"></span><br><span class="line"><span class="string">driver:&quot;syslog&quot;</span></span><br><span class="line"><span class="attr">options:</span></span><br><span class="line">  <span class="string">syslog-address:&quot;tcp://192.168.0.42:123&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">默认驱动程序</span> <span class="string">json-file</span>  <span class="string">具有限制存储日志量的选项，所以，使用键值对来获得最大存储大小以及最小存储数量</span></span><br><span class="line"></span><br><span class="line"><span class="attr">driver:</span> <span class="string">&quot;json-file&quot;</span></span><br><span class="line"><span class="attr">options:</span></span><br><span class="line">  <span class="string">max-size:&quot;200k&quot;</span></span><br><span class="line">  <span class="string">max-file:&quot;10&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">上面实例将存储日志文件，直到它们达到max-size:200kB，存储的单个日志文件的数量由该</span> <span class="string">max-file</span> <span class="string">值指定。随着日志增长超出最大限制，旧日志文件将被删除以存储新日志</span></span><br><span class="line"><span class="string">docker-compose.yml</span> <span class="string">限制日志存储的示例</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">some-service:</span></span><br><span class="line">    <span class="string">image:some-service</span></span><br><span class="line">    <span class="attr">logging:</span></span><br><span class="line">      <span class="string">driver:&quot;json-file&quot;</span></span><br><span class="line">      <span class="attr">options:</span></span><br><span class="line">        <span class="string">max-size:&quot;200k&quot;</span></span><br><span class="line">        <span class="string">max-file:&quot;10&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.32</span> <span class="string">network_mode</span></span><br><span class="line"><span class="string">网络模式，用法类似于</span> <span class="string">Docke</span> <span class="string">客户端的</span> <span class="string">--net</span> <span class="string">选项，格式为：service:[service</span> <span class="string">name]，可以指定使用服务或者容器的网络。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">network_mode:</span> <span class="string">&quot;bridge&quot;</span></span><br><span class="line"><span class="attr">network_mode:</span> <span class="string">&quot;host&quot;</span></span><br><span class="line"><span class="attr">network_mode:</span> <span class="string">&quot;none&quot;</span></span><br><span class="line"><span class="attr">network_mode:</span> <span class="string">&quot;service:[service name]&quot;</span></span><br><span class="line"><span class="attr">network_mode:</span> <span class="string">&quot;container:[container name/id]&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.33</span> <span class="string">networks</span></span><br><span class="line"><span class="string">加入指定网络</span></span><br><span class="line"></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">some-service:</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">     <span class="string">-some-network</span></span><br><span class="line">     <span class="string">-other-network</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.34</span> <span class="string">aliases</span></span><br><span class="line"><span class="string">同一网络上的其他容器可以使用服务器名称或别名来连接到其他服务的容器，相同的服务可以在不同的网络有不同的别名。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">some-service:</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="attr">some-network:</span></span><br><span class="line">        <span class="attr">aliases:</span></span><br><span class="line">         <span class="string">-alias1</span></span><br><span class="line">         <span class="string">-alias3</span></span><br><span class="line">      <span class="attr">other-network:</span></span><br><span class="line">        <span class="attr">aliases:</span></span><br><span class="line">         <span class="string">-alias2</span></span><br><span class="line"></span><br><span class="line"><span class="string">下面实例中，提供</span> <span class="string">web</span> <span class="string">、worker以及db</span> <span class="string">服务，伴随着两个网络</span> <span class="string">new</span> <span class="string">和</span> <span class="string">legacy</span> <span class="string">。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="string">image:&quot;nginx:alpine&quot;</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="string">-new</span></span><br><span class="line"> </span><br><span class="line">  <span class="attr">worker:</span></span><br><span class="line">    <span class="string">image:&quot;my-worker-image:latest&quot;</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="string">-legacy</span></span><br><span class="line"> </span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="string">image:mysql</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="attr">new:</span></span><br><span class="line">        <span class="attr">aliases:</span></span><br><span class="line">          <span class="string">-database</span></span><br><span class="line">      <span class="attr">legacy:</span></span><br><span class="line">        <span class="attr">aliases:</span></span><br><span class="line">          <span class="string">-mysql</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">new:</span></span><br><span class="line">  <span class="attr">legacy:</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.35</span> <span class="string">ipv4_address、ipv6_address</span></span><br><span class="line"><span class="string">为服务的容器指定一个静态</span> <span class="string">IP</span> <span class="string">地址</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">app:</span></span><br><span class="line">    <span class="string">image:nginx:alpine</span></span><br><span class="line">    <span class="attr">networks:</span></span><br><span class="line">      <span class="attr">app_net:</span></span><br><span class="line">        <span class="string">ipv4_address:172.16.238.10</span></span><br><span class="line">        <span class="string">ipv6_address:2001:3984:3989::10</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">app_net:</span></span><br><span class="line">    <span class="attr">ipam:</span></span><br><span class="line">      <span class="string">driver:default</span></span><br><span class="line">      <span class="attr">config:</span></span><br><span class="line">        <span class="string">-subnet:&quot;172.16.238.0/24&quot;</span></span><br><span class="line">        <span class="string">-subnet:&quot;2001:3984:3989::/64&quot;</span></span><br><span class="line"><span class="number">2.36</span> <span class="string">pid</span></span><br><span class="line"></span><br><span class="line"><span class="string">将</span> <span class="string">PID</span> <span class="string">模式设置为主机</span> <span class="string">PID</span> <span class="string">模式，可以打开容器与主机操作系统之间的共享</span> <span class="string">PID</span> <span class="string">地址空间。使用此标志启动的容器可以访问和操作宿主机的其他容器，反之亦然</span></span><br><span class="line"><span class="attr">pid:</span> <span class="string">&quot;host&quot;</span></span><br><span class="line"><span class="number">2.37</span> <span class="string">ports</span></span><br><span class="line"><span class="string">映射端口</span></span><br><span class="line"><span class="number">2.37</span><span class="number">.1</span> <span class="string">SHORT</span> <span class="string">语法</span></span><br><span class="line"><span class="string">可以使用</span> <span class="string">HOST:CONTAINER</span> <span class="string">的方式指定端口，也可以指定容器端口（选择临时主机端口），宿主机会随机映射端口</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ports:</span></span><br><span class="line"> <span class="string">-&quot;3000&quot;</span></span><br><span class="line"> <span class="string">-&quot;3000-3005&quot;</span></span><br><span class="line"> <span class="string">-&quot;8000:8000&quot;</span></span><br><span class="line"> <span class="string">-&quot;9090-9091:8080-8081&quot;</span></span><br><span class="line"> <span class="string">-&quot;49100:22&quot;</span></span><br><span class="line"> <span class="string">-&quot;127.0.0.1:8001:8001&quot;</span></span><br><span class="line"> <span class="string">-&quot;127.0.0.1:5000-5010:5000-5010&quot;</span></span><br><span class="line"> <span class="string">-&quot;6060:6060/udp&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：当使用</span> <span class="string">HOST:CONTAINER</span> <span class="string">格式来映射端口时，如果使用的容器端口小于60可能会得到错误得结果，因为YAML</span> <span class="string">将会解析</span> <span class="string">xx:yy</span> <span class="string">这种数字格式为</span> <span class="number">60</span> <span class="string">进制，所以建议采用字符串格式。</span></span><br><span class="line"><span class="number">2.37</span><span class="number">.3</span> <span class="string">LONG语法</span></span><br><span class="line"><span class="string">LONG</span> <span class="string">语法支持</span> <span class="string">SHORT</span> <span class="string">语法不支持的附加字段</span></span><br><span class="line"><span class="string">target：容器内的端口</span></span><br><span class="line"><span class="string">published：公开的端口</span></span><br><span class="line"><span class="string">protocol：</span>  <span class="string">端口协议（tcp</span> <span class="string">或</span> <span class="string">udp）</span></span><br><span class="line"><span class="string">mode：通过host</span> <span class="string">用在每个节点还是哪个发布的主机端口或使用</span> <span class="string">ingress</span> <span class="string">用于集群模式端口进行平衡负载</span></span><br><span class="line"></span><br><span class="line"><span class="attr">ports:</span></span><br><span class="line">  <span class="string">-target:80</span></span><br><span class="line">    <span class="string">published:8080</span></span><br><span class="line">    <span class="string">protocol:tcp</span></span><br><span class="line">    <span class="string">mode:host</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.38</span> <span class="string">restart</span></span><br><span class="line"><span class="string">默认值为</span> <span class="literal">no</span> <span class="string">，即在任何情况下都不会重新启动容器；当值为</span> <span class="string">always</span> <span class="string">时，容器总是重新启动；当值为</span> <span class="string">on-failure</span> <span class="string">时，当出现</span> <span class="string">on-failure</span> <span class="string">报错容器退出时，容器重新启动。</span></span><br><span class="line"></span><br><span class="line"><span class="attr">restart:</span> <span class="string">&quot;no&quot;</span></span><br><span class="line"><span class="attr">restart:</span> <span class="string">always</span></span><br><span class="line"><span class="attr">restart:</span> <span class="string">on-failure</span></span><br><span class="line"><span class="attr">restart:</span> <span class="string">unless-stopped</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.40</span> <span class="string">secrets</span></span><br><span class="line"><span class="string">通过</span> <span class="string">secrets为每个服务授予相应的访问权限</span></span><br><span class="line"><span class="number">2.40</span><span class="number">.1</span> <span class="string">SHORT语法</span></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:latest</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:1</span></span><br><span class="line">    <span class="attr">secrets:</span></span><br><span class="line">      <span class="string">-my_secret</span></span><br><span class="line">      <span class="string">-my_other_secret</span></span><br><span class="line"><span class="attr">secrets:</span></span><br><span class="line">  <span class="attr">my_secret:</span></span><br><span class="line">    <span class="string">file:./my_secret.txt</span></span><br><span class="line">  <span class="attr">my_other_secret:</span></span><br><span class="line">    <span class="string">external:true</span></span><br><span class="line"><span class="number">2.40</span><span class="number">.2</span> <span class="string">LONG语法</span></span><br><span class="line"><span class="string">LONG</span> <span class="string">语法可以添加其他选项</span></span><br><span class="line"><span class="string">source：secret</span> <span class="string">名称</span></span><br><span class="line"><span class="string">target：在服务任务容器中需要装载在</span> <span class="string">/run/secrets/</span> <span class="string">中的文件名称，如果</span> <span class="string">source</span> <span class="string">未定义，那么默认为此值</span></span><br><span class="line"><span class="string">uid&amp;gid：在服务的任务容器中拥有该文件的</span> <span class="string">UID</span> <span class="string">或</span> <span class="string">GID</span> <span class="string">。如果未指定，两者都默认为</span> <span class="number">0</span><span class="string">。</span></span><br><span class="line"><span class="string">mode：以八进制表示法将文件装载到服务的任务容器中</span> <span class="string">/run/secrets/</span> <span class="string">的权限。例如，0444</span> <span class="string">代表可读。</span></span><br><span class="line"></span><br><span class="line"><span class="string">version:&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">redis:</span></span><br><span class="line">    <span class="string">image:redis:latest</span></span><br><span class="line">    <span class="attr">deploy:</span></span><br><span class="line">      <span class="string">replicas:1</span></span><br><span class="line">    <span class="attr">secrets:</span></span><br><span class="line">      <span class="string">-source:my_secret</span></span><br><span class="line">        <span class="string">target:redis_secret</span></span><br><span class="line">        <span class="string">uid:&#x27;103&#x27;</span></span><br><span class="line">        <span class="string">gid:&#x27;103&#x27;</span></span><br><span class="line">        <span class="string">mode:0440</span></span><br><span class="line"><span class="attr">secrets:</span></span><br><span class="line">  <span class="attr">my_secret:</span></span><br><span class="line">    <span class="string">file:./my_secret.txt</span></span><br><span class="line">  <span class="attr">my_other_secret:</span></span><br><span class="line">    <span class="string">external:true</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.41</span> <span class="string">security_opt</span></span><br><span class="line"><span class="string">为每个容器覆盖默认的标签。简单说来就是管理全部服务的标签，比如设置全部服务的</span> <span class="string">user</span> <span class="string">标签值为</span> <span class="string">USER</span></span><br><span class="line"></span><br><span class="line"><span class="attr">security_opt:</span></span><br><span class="line">  <span class="string">-label:user:USER</span></span><br><span class="line">  <span class="string">-label:role:ROLE</span></span><br><span class="line"><span class="number">2.42</span> <span class="string">stop_grace_period</span></span><br><span class="line"><span class="string">在发送</span> <span class="string">SIGKILL</span> <span class="string">之前指定</span> <span class="string">stop_signal</span> <span class="string">，如果试图停止容器（如果它没有处理</span> <span class="string">SIGTERM（或指定的任何停止信号）），则需要等待的时间</span> </span><br><span class="line"></span><br><span class="line"><span class="attr">stop_grace_period:</span> <span class="string">1s</span></span><br><span class="line"><span class="attr">stop_grace_period:</span> <span class="string">1m30s</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.43</span> <span class="string">stop_signal</span></span><br><span class="line"><span class="string">设置另一个信号来停止容器。在默认情况下使用的</span> <span class="string">SIGTERM</span> <span class="string">来停止容器。设置另一个信号可以使用</span> <span class="string">stop_signal</span> <span class="string">标签：</span></span><br><span class="line"></span><br><span class="line"><span class="string">stop_signal:SIGUSR1</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.44</span> <span class="string">sysctls</span></span><br><span class="line"><span class="string">在容器中设置的内核参数，可以为数组或字典</span></span><br><span class="line"><span class="attr">sysctls:</span></span><br><span class="line">  <span class="attr">net.core.somaxconn:</span> <span class="number">1024</span></span><br><span class="line">  <span class="attr">net.ipv4.tcp_syncookies:</span> <span class="number">0</span></span><br><span class="line"><span class="attr">sysctls:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">net.core.somaxconn=1024</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">net.ipv4.tcp_syncookies=0</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：使用（版本3）Compose文件在群集模式下部署堆栈时，将忽略此选项</span></span><br><span class="line"><span class="number">2.45</span> <span class="string">tmpfs</span></span><br><span class="line"><span class="string">挂载临时文件目录到容器内部，与</span> <span class="string">run</span> <span class="string">的参数一样效果，可以是单个值或列表</span></span><br><span class="line"><span class="attr">tmpfs:</span> <span class="string">/run</span></span><br><span class="line"><span class="attr">tmpfs:</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">/run</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">/tmp</span></span><br><span class="line"><span class="string">在容器内安装临时文件系统。Size参数指定tmpfs</span> <span class="string">mount的大小（以字节为单位）。默认无限制。</span></span><br><span class="line"><span class="bullet">-</span> <span class="attr">type:</span> <span class="string">tmpfs</span></span><br><span class="line">     <span class="attr">target:</span> <span class="string">/app</span></span><br><span class="line">     <span class="attr">tmpfs:</span></span><br><span class="line">       <span class="attr">size:</span> <span class="number">1000</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：使用（版本3-3.5）Compose文件在群集模式下部署堆栈时，将忽略此选项</span>  <span class="string">。</span></span><br><span class="line"><span class="number">2.46</span> <span class="string">ulimits</span></span><br><span class="line"><span class="string">覆盖容器的默认限制，可以单一地将限制值设为一个整数，也可以将soft/hard</span> <span class="string">限制指定为映射</span></span><br><span class="line"><span class="attr">ulimits:</span></span><br><span class="line">  <span class="attr">nproc:</span> <span class="number">65535</span></span><br><span class="line">  <span class="attr">nofile:</span></span><br><span class="line">    <span class="attr">soft:</span> <span class="number">20000</span></span><br><span class="line">    <span class="attr">hard:</span> <span class="number">40000</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.47</span> <span class="string">userns_mode</span></span><br><span class="line"><span class="string">如果Docker守护程序配置了用户名称空间，则禁用此服务的用户名称空间。</span></span><br><span class="line"><span class="attr">userns_mode:</span> <span class="string">&quot;host&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="string">注意：使用（版本3）Compose文件在群集模式下部署堆栈时，将忽略此选项</span> <span class="string">。</span></span><br><span class="line"><span class="number">2.48</span>  <span class="string">volumes</span></span><br><span class="line"><span class="string">挂载一个目录或者一个已存在的数据卷容器，可以直接使用</span> <span class="string">HOST:CONTAINER</span> <span class="string">这样的格式，或者使用</span> <span class="string">HOST:CONTAINER:ro</span> <span class="string">这样的格式，后者对于容器来说，数据卷是只读的，这样可以有效保护宿主机的文件系统</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">nginx:alpine</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">type:</span> <span class="string">volume</span></span><br><span class="line">        <span class="attr">source:</span> <span class="string">mydata</span></span><br><span class="line">        <span class="attr">target:</span> <span class="string">/data</span></span><br><span class="line">        <span class="attr">volume:</span></span><br><span class="line">          <span class="attr">nocopy:</span> <span class="literal">true</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">type:</span> <span class="string">bind</span></span><br><span class="line">        <span class="attr">source:</span> <span class="string">./static</span></span><br><span class="line">        <span class="attr">target:</span> <span class="string">/opt/app/static</span></span><br><span class="line"> </span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">postgres:latest</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;/var/run/postgres/postgres.sock:/var/run/postgres/postgres.sock&quot;</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;dbdata:/var/lib/postgresql/data&quot;</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">mydata:</span></span><br><span class="line">  <span class="attr">dbdata:</span></span><br><span class="line"></span><br><span class="line"><span class="string">此示例显示服务使用的命名卷（mydata）web以及为单个服务（db服务</span> <span class="string">下的第一个路径volumes）定义的绑定安装。该db服务还使用名为dbdata（db服务中的第二个路径volumes）的命名卷，但使用旧字符串格式定义它以安装命名卷。必须在顶级volumes键下列出命名卷</span></span><br><span class="line"><span class="number">2.48</span><span class="number">.1</span> <span class="string">SHORT语法</span></span><br><span class="line"><span class="string">可以选择在主机（HOST:CONTAINER）或访问模式（HOST:CONTAINER:ro）上指定路径。</span></span><br><span class="line"><span class="string">可以在主机上挂载相对路径，该路径相对于正在使用的</span> <span class="string">Compose</span> <span class="string">配置文件的目录进行扩展。相对路径应始终以</span> <span class="string">.</span> <span class="string">或</span> <span class="string">..</span> <span class="string">开头</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="comment"># Just specify a path and let the Engine create a volume</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">/var/lib/mysql</span></span><br><span class="line"> </span><br><span class="line">  <span class="comment"># Specify an absolute path mapping</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">/opt/data:/var/lib/mysql</span></span><br><span class="line"> </span><br><span class="line">  <span class="comment"># Path on the host, relative to the Compose file</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">./cache:/tmp/cache</span></span><br><span class="line"> </span><br><span class="line">  <span class="comment"># User-relative path</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">~/configs:/etc/configs/:ro</span></span><br><span class="line"> </span><br><span class="line">  <span class="comment"># Named volume</span></span><br><span class="line">  <span class="bullet">-</span> <span class="string">datavolume:/var/lib/mysql</span></span><br><span class="line"><span class="number">2.48</span><span class="number">.2</span> <span class="string">LONG语法</span></span><br><span class="line"><span class="string">LONG</span> <span class="string">语法有些附加字段</span></span><br><span class="line"><span class="string">type：安装类型，可以为</span> <span class="string">volume、bind</span> <span class="string">或</span> <span class="string">tmpfs</span></span><br><span class="line"><span class="string">source：安装源，主机上用于绑定安装的路径或定义在顶级</span> <span class="string">volumes密钥中卷的名称</span> <span class="string">,不适用于</span> <span class="string">tmpfs</span> <span class="string">类型安装。</span></span><br><span class="line"><span class="string">target：卷安装在容器中的路径</span></span><br><span class="line"><span class="string">read_only：标志将卷设置为只读</span></span><br><span class="line"><span class="string">bind：配置额外的绑定选项</span></span><br><span class="line"><span class="string">propagation：用于绑定的传播模式</span></span><br><span class="line"><span class="string">volume：配置其他卷选项</span></span><br><span class="line"><span class="string">nocopy：创建卷时禁止从容器复制数据的标志</span></span><br><span class="line"><span class="string">tmpfs：配置额外的</span> <span class="string">tmpfs</span> <span class="string">选项</span></span><br><span class="line"><span class="string">size：tmpfs</span> <span class="string">的大小，以字节为单位</span></span><br><span class="line"><span class="string">consistent：完全一致。容器运行时和主机始终保持相同的安装视图。这是默认值。</span></span><br><span class="line"><span class="string">cached：主机的mount视图是权威的。在主机上进行的更新在容器中可见之前可能会有延迟。</span></span><br><span class="line"><span class="string">delegated：容器运行时的mount视图是权威的。在容器中进行的更新在主机上可见之前可能会有延迟。</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">web:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">nginx:alpine</span></span><br><span class="line">    <span class="attr">ports:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">&quot;80:80&quot;</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">type:</span> <span class="string">volume</span></span><br><span class="line">        <span class="attr">source:</span> <span class="string">mydata</span></span><br><span class="line">        <span class="attr">target:</span> <span class="string">/data</span></span><br><span class="line">        <span class="attr">volume:</span></span><br><span class="line">          <span class="attr">nocopy:</span> <span class="literal">true</span></span><br><span class="line">      <span class="bullet">-</span> <span class="attr">type:</span> <span class="string">bind</span></span><br><span class="line">        <span class="attr">source:</span> <span class="string">./static</span></span><br><span class="line">        <span class="attr">target:</span> <span class="string">/opt/app/static</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">networks:</span></span><br><span class="line">  <span class="attr">webnet:</span></span><br><span class="line"> </span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">mydata:</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.49</span> <span class="string">driver</span></span><br><span class="line"><span class="string">指定应为此卷使用哪个卷驱动程序。默认为Docker</span> <span class="string">Engine配置使用的任何驱动程序，在大多数情况下是local。如果驱动程序不可用，则在docker-compose</span> <span class="string">up尝试创建卷时Engine会返回错误</span> <span class="string">。</span></span><br><span class="line"><span class="attr">driver:</span> <span class="string">foobar</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.50</span> <span class="string">driver_opts</span></span><br><span class="line"><span class="string">将选项列表指定为键值对，以传递给此卷的驱动程序。</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">example:</span></span><br><span class="line">    <span class="attr">driver_opts:</span></span><br><span class="line">      <span class="attr">type:</span> <span class="string">&quot;nfs&quot;</span></span><br><span class="line">      <span class="attr">o:</span> <span class="string">&quot;addr=10.40.0.199,nolock,soft,rw&quot;</span></span><br><span class="line">      <span class="attr">device:</span> <span class="string">&quot;:/docker/example&quot;</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.51</span> <span class="string">external</span></span><br><span class="line"><span class="string">如果设置为true，则指定已在Compose之外创建此卷。docker-compose</span> <span class="string">up不会尝试创建它，如果它不存在则引发错误。</span></span><br><span class="line"><span class="string">在下面的示例中，[projectname]_dataCompose</span> <span class="string">不是尝试创建一个被调用的卷，而是</span> <span class="string">查找简单调用的现有卷data并将其挂载到db服务的容器中。</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">services:</span></span><br><span class="line">  <span class="attr">db:</span></span><br><span class="line">    <span class="attr">image:</span> <span class="string">postgres</span></span><br><span class="line">    <span class="attr">volumes:</span></span><br><span class="line">      <span class="bullet">-</span> <span class="string">data:/var/lib/postgresql/data</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">external:</span> <span class="literal">true</span></span><br><span class="line"><span class="string">还可以在Compose文件中与用于引用它的名称分别指定卷的名称：</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">external:</span></span><br><span class="line">      <span class="attr">name:</span> <span class="string">actual-name-of-volume</span></span><br><span class="line"></span><br><span class="line"><span class="number">2.52</span> <span class="string">name</span></span><br><span class="line"><span class="string">为此卷设置自定义名称。name字段可用于引用包含特殊字符的卷。该名称按原样使用，不会使用堆栈名称作为范围。</span></span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">my-app-data</span></span><br><span class="line"><span class="string">它也可以与external参数一起使用：</span> </span><br><span class="line"><span class="attr">version:</span> <span class="string">&quot;3.7&quot;</span></span><br><span class="line"><span class="attr">volumes:</span></span><br><span class="line">  <span class="attr">data:</span></span><br><span class="line">    <span class="attr">external:</span> <span class="literal">true</span></span><br><span class="line">    <span class="attr">name:</span> <span class="string">my-app-data</span></span><br><span class="line">    </span><br><span class="line">    </span><br><span class="line"><span class="number">3.01</span> <span class="string">命令使用</span></span><br><span class="line"><span class="string">命令对象与格式</span></span><br><span class="line"></span><br><span class="line"><span class="string">对于</span> <span class="string">Compose</span> <span class="string">来说，大部分命令的对象既可以是项目本身，也可以指定为项目中的服务或者容器。若没有特别说明，命令</span></span><br><span class="line"></span><br><span class="line"><span class="string">对象将是项目，这意味着项目中所有的服务都会受到命令影响</span></span><br><span class="line"></span><br><span class="line"><span class="string">执行</span> <span class="string">docker-compose</span> [<span class="string">COMMAND</span>] <span class="string">--help</span> <span class="string">或者</span> <span class="string">docker-compose</span> <span class="string">help</span> [<span class="string">COMMAND</span>] <span class="string">可以查看具体某个命令的使用格式。如下：</span></span><br><span class="line"></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">--help</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="string">docker-compose命令的基本使用格式是：</span></span><br><span class="line"></span><br><span class="line"><span class="string">docker-compose</span> [<span class="string">-f=&lt;arg&gt;...</span>] [<span class="string">options</span>] [<span class="string">COMMAND</span>] [<span class="string">ARGS...</span>]</span><br><span class="line"><span class="string">命令选项</span></span><br><span class="line"></span><br><span class="line"><span class="string">-f,</span> <span class="string">--file</span> <span class="string">FILE</span> <span class="string">指定使用的</span> <span class="string">Compose</span> <span class="string">模板文件，默认为</span> <span class="string">docker-compose.yml，可以多次指定；</span></span><br><span class="line"><span class="string">-p,</span> <span class="string">--project-name</span> <span class="string">NAME</span> <span class="string">指定项目名称，默认将使用所在目录名称作为项目名；</span></span><br><span class="line"><span class="string">--x-networking</span> <span class="string">使用</span> <span class="string">Docker</span> <span class="string">的可拔插网络后端特性；</span></span><br><span class="line"><span class="string">--x-network-driver</span> <span class="string">DRIVER</span> <span class="string">指定网络后端的驱动，默认为</span> <span class="string">bridge；</span></span><br><span class="line"><span class="string">--verbose</span> <span class="string">输出更多调试信息；</span></span><br><span class="line"><span class="string">-v,</span> <span class="string">--version</span> <span class="string">打印版本并退出；</span></span><br><span class="line"><span class="string">常用命令</span></span><br><span class="line"></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">命令</span> <span class="string">--help</span>                    <span class="string">获得一个命令的帮助</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">up</span> <span class="string">-d</span> <span class="string">nginx</span>                    <span class="string">构建启动nignx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">exec</span> <span class="string">nginx</span> <span class="string">bash</span>                <span class="string">登录到nginx容器中</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">down</span>                           <span class="string">此命令将会停止</span> <span class="string">up</span> <span class="string">命令所启动的容器，并移除网络</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">ps</span>                             <span class="string">列出项目中目前的所有容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">restart</span> <span class="string">nginx</span>                  <span class="string">重新启动nginx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">build</span> <span class="string">nginx</span>                    <span class="string">构建镜像</span> </span><br><span class="line"><span class="string">docker-compose</span> <span class="string">build</span> <span class="string">--no-cache</span> <span class="string">nginx</span>         <span class="string">不带缓存的构建</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">top</span>                            <span class="string">查看各个服务容器内运行的进程</span> </span><br><span class="line"><span class="string">docker-compose</span> <span class="string">logs</span> <span class="string">-f</span> <span class="string">nginx</span>                  <span class="string">查看nginx的实时日志</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">images</span>                         <span class="string">列出</span> <span class="string">Compose</span> <span class="string">文件包含的镜像</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">config</span>                         <span class="string">验证文件配置，当配置正确时，不输出任何内容，当文件配置错误，输出错误信息。</span> </span><br><span class="line"><span class="string">docker-compose</span> <span class="string">events</span> <span class="string">--json</span> <span class="string">nginx</span>            <span class="string">以json的形式输出nginx的docker日志</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">pause</span> <span class="string">nginx</span>                    <span class="string">暂停nignx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">unpause</span> <span class="string">nginx</span>                  <span class="string">恢复ningx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">rm</span> <span class="string">nginx</span>                       <span class="string">删除容器（删除前必须关闭容器，执行stop）</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">stop</span> <span class="string">nginx</span>                     <span class="string">停止nignx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">start</span> <span class="string">nginx</span>                    <span class="string">启动nignx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">restart</span> <span class="string">nginx</span>                  <span class="string">重启项目中的nignx容器</span></span><br><span class="line"><span class="string">docker-compose</span> <span class="string">run</span> <span class="string">--no-deps</span> <span class="string">--rm</span> <span class="string">php-fpm</span> <span class="string">php</span> <span class="string">-v</span>   <span class="string">在php-fpm中不启动关联容器，并容器执行php</span> <span class="string">-v</span> <span class="string">执行完成后删除容器</span></span><br><span class="line"><span class="number">4.01</span> <span class="string">文章参考：</span></span><br><span class="line"><span class="string">https://www.cnblogs.com/wutao666/p/11332186.html</span></span><br><span class="line"><span class="string">https://www.sitven.cn/blog/106</span></span><br></pre></td></tr></table></figure> 
      <!-- reward -->
      
      <div id="reword-out">
        <div id="reward-btn">
          打赏
        </div>
      </div>
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>版权声明： </strong>
          
          本博客所有文章除特别声明外，著作权归作者所有。转载请注明出处！
          
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="//api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://example.com/2020/11/11/docker/%E6%9C%80%E6%96%B0%E6%95%B4%E7%90%86%E4%B9%8B--docker-compose%E5%8F%82%E6%95%B0%E5%8F%8A%E5%91%BD%E4%BB%A4/" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
  <ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/docker/" rel="tag">docker</a></li></ul>

    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/11/11/other/%E5%8E%9F%E6%9D%A5%208%20%E5%BC%A0%E5%9B%BE%EF%BC%8C%E5%B0%B1%E5%8F%AF%E4%BB%A5%E6%90%9E%E6%87%82%E3%80%8C%E9%9B%B6%E6%8B%B7%E8%B4%9D%E3%80%8D%E4%BA%86/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            原来 8 张图，就可以搞懂「零拷贝」了.md
          
        </div>
      </a>
    
    
      <a href="/2020/11/11/es/Elasticsearch%20%E6%9C%80%E4%BD%B3%E5%AE%9E%E8%B7%B5/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">Elasticsearch 最佳实践.md</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "",
    app_key: "",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "给我的文章加点评论吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> TzWind
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        由 <a href="https://hexo.io" target="_blank">Hexo</a> 强力驱动
        <span class="division">|</span>
        主题 - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>访问人数:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>浏览次数:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/ayer-side.svg" alt="Hexo"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" target="_blank" rel="noopener" href="http://www.baidu.com">百度</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/friends">友链</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/2019/about">关于我</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="搜索">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>